<?php
/*****************************************************************
	Std PHP Framework
	Module Common 
	$Id: mod_common.php 4 2008-02-25 23:18:23Z RusAnon $
*****************************************************************/
/*****************************************************************
	Module Common Configuration
*****************************************************************/
/*
define("ModCommon_STR_alphanumeric",		"QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890");
$alphabet = ModCommon_STR_alphanumeric;
*/
function plaintext($text)
{
	return $text;
}
function GetRandomString($l,$a="")
{
	global $alphabet;
	if (!$a)
		$a = $alphabet;
	$s = "";
	$al = strlen($a)-1;
	for ($i=0;$i<$l;$i++)
	{
		$s.=$a{rand(0,$al)};
	}
	return $s;
}
function ValidateArrayByTemplate($a,$t)
{
	$r = array();
	foreach ($t as $k => $v)
	{
		if (isset($a[$k]))
		{
			if(is_array($v))
			{
				$r[$k]=ValidateArrayByTemplate($a[$k],$v);
			}
			else
			{
				$r[$k]=$a[$k];
			}
		}
		else
		{
			$r[$k]=$v;
		}
	}
	return $r;
}
function RNGPickGroupByRate($groups)
{
	$TotalRate = 0;
	krsort($groups);
	foreach($groups as $rate => $grp)
	{
		$TotalRate += $rate;
	}
	$rnd = rand(1000,$TotalRate*1000)/1000;
	$boundary = 0;
	foreach($groups as $rate => $grp)
	{
		$rr = $TotalRate / $rate;
		$boundary += $rr;
		if ($rnd <= $boundary)
			return $grp;
	}
	return end($groups);
}
?>